import Vue from 'vue'
import Vuex from 'vuex'
import axios from 'axios'
Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    list:[],
    conList:[],
    cardInfo:[],//银行卡信息
    recharge:[]//充值总额
  },
  getters:{
     allNum(state){
       let countNum=0;
       state.recharge.forEach(item=>{
        countNum+=item.num;
       })
        // console.log(countNum,'ccccc')
       return countNum
      
     }
  },
  mutations: {
    GET_LIST(state,data){
      state.list=data
      console.log(state.list,'xx')
    },
    CON_LIST(state,data){
      state.conList=data
    },
    GET_CARDINFO(state,actions){//存储银行卡信息
      state.cardInfo.push(actions)
    },
   ADD_RECHARGE(state,data){
       state.recharge=data
    }
  },
  actions: {
    //获取第一层数据
    getList(context,data){
      context.commit('GET_LIST',data)
    },
    //获取第二层数据
    conList(context,data){
      context.commit("CON_LIST",data)
    },
    async getRecharge({commit}){
      const res=await axios('/getRecharge')
      console.log(res,'res')
      commit('ADD_RECHARGE',res.data.list)
   }
    
  },
})


